<template>
  <div class="g-bd" id="m-disc-pl-c">
    <div class="g-wrap p-pl f-pr">
      <div class="u-title f-cb">
        <h3>
          <span class="f-ff2 d-flag">歌单</span>
          <a href="javascript:;" class="menu d-flag tag-cascader-warp" id="cateToggleLink">
            <!--<i>选择分类<em class="u-icn u-icn-38"></em></i>-->
            <el-cascader
              :options="options"
              :show-all-levels="false"
              size="small" class="tag-cascader" @change="tagChange">

            </el-cascader>
          </a>
        </h3>
        <div class="u-btn f-fr d-flag" :class="orderType === 'hot' ? 'u-btn-hot' : 'u-btn-time'" >
          <a :class="orderType === 'hot' ? 'a1' : 'a2'" data-order="hot" @click="changeToHot">热门</a>
          <a :class="orderType === 'hot' ? 'a2' : 'a1'" data-order="new" @click="changeToTime">最新</a>
        </div>
      </div>
      <ul class="m-cvrlst f-cb" id="m-pl-container">
        <li v-for="(i, index) in list">
          <div class="u-cover u-cover-1">
            <img class="j-flag"
                 :src="changeUrlToResizeImg(i.coverImgUrl, 140)">
            <router-link :to="{path:'playlistDetail',query:{id:i.id}}" :title="i.name" class="msk">
            </router-link>
            <div class="bottom">
              <a class="icon-play f-fr" title="播放" href="javascript:;" data-res-type="13" data-res-id="i.id"
                 data-res-action="play"></a>
              <span class="icon-headset"></span>
              <span class="nb">{{i.playCount}}</span>
            </div>
          </div>
          <p class="dec">
            <router-link :to="{path:'playlistDetail',query:{id:i.id}}" :title="i.name" class="tit f-thide s-fc0">
              {{i.name}}
            </router-link>
          </p>
          <p><span class="s-fc4">by</span>
            <router-link :to="{path:'userHome',query:{id:i.userVO.id}}" :title="i.userVO.nickname" class="nm nm-icn f-thide s-fc3">
              {{i.userVO.nickname}}
            </router-link>
            <sup class="u-icn u-icn-84 "></sup>
          </p>
        </li>
      </ul>
      <!--<pagination :page-num="pageNum" :pages="pages" :get-data-with-page-num="getPlaylists"></pagination>-->
      <pagination-with-tag :page-num="pageNum" :pages="pages" :tag="tag" :get-data-with-page-num="getPlaylists"></pagination-with-tag>
    </div>
  </div>
</template>

<script>

  import {playlist, getPlaylistsByTagId} from  './../service/getData';
  import Pagination from '../components/pagination'
  import PaginationWithTag from '../components/paginationWithTag'
  //  import Vue from 'vue'
  //  import Router from 'vue-router';
  //
  //  Vue.use(Router);
  export default {
    name: 'playlist',
    data () {
      return {
//        msg: 'this is the content of area'
        list: [],
        pageNum: 1, // 当前页数
        pages: 1,  // 总页数
        options: [{
          value: "all",
          label: "全部"
        },{
          value: "lang",
          label: "语种",
          children: [{
            value: "4121962400414957569",
            label: "华语"
          }, {
            value: "4121962400838582273",
            label: "欧美"
          }, {
            value: "4121962401417396225",
            label: "日语"
          }, {
            value: "4121962405313904641",
            label: "韩语"
          }, {
            value: "4121962407125843969",
            label: "粤语"
          }]
        }, {
          value: "style",
          label: "风格",
          children: [{
            value: "4121962400712753153",
            label: "流行"
          }, {
            value: "4121962429208854529",
            label: "摇滚"
          }, {
            value: "4121962400813416449",
            label: "民谣"
          }, {
            value: "4121962401295761409",
            label: "电子"
          }, {
            value: "4121962407532691457",
            label: "说唱"
          }]
        }],
        orderType: "hot",
        getPlaylists: this.getPlaylistsWithPageNum,
        tag: null
      }
    },
    methods: {
       changeUrlToResizeImg(picUrl, size) {
          return picUrl.replace(/yunmusic_dev/, "resize_" + size + 'x' + size);
      },
      changeToTime() {
        if (this.orderType !== 'time') {
          this.orderType = 'time';
          this.getPlaylistsWithPageNum(1)
        }
      },
      changeToHot() {
        if (this.orderType !== 'hot') {
          this.orderType = 'hot';
          this.getPlaylistsWithPageNum(1)
        }
      },
      tagChange(value) {
        console.log(value)
        this.list = [];
        this.pageNum= 1;
        if (value[0] === 'all') {
          this.getPlaylistsWithPageNum(this.pageNum)
          this.getPlaylists = this.getPlaylistsWithPageNum
        } else {
          let tagId = value[1]
          this.getPlaylistsByTagIdWithPageNum(this.pageNum, tagId)
          this.getPlaylists = this.getPlaylistsByTagIdWithPageNum
        }
      },
      getPlaylistsByTagIdWithPageNum(pageNum, tagId) {
        this.tag = tagId;
        let _this = this;
        _this.list = [];
        getPlaylistsByTagId(this).get({
          page: pageNum,
          pageSize: 15,
          tagId: tagId
        }).then(res => {
          console.log(res);
          let status = res.body.status;
          if (status === 200) {
            let data = res.body.data;
            _this.pageNum = data.page;
            _this.pages = data.pages;
            _this.list = data.rows;
          }
        });
      },
      getPlaylistsWithPageNum (pageNum) {
        let _this = this;
        _this.list = [];
        playlist(this).get({
          playlist: 'playlist',
          pageNum: pageNum,
          pageSize: 15,
          order: this.orderType
        }).then(res => {
          console.log(res);
          let status = res.body.status;
          if (status === 200) {
            let data = res.body.data;
            _this.pageNum = data.page;
            _this.pages = data.pages;
            _this.list = data.rows;
          }
        });
      }
//      turn (id) {
//        console.log(id)
//        this.$router.push({ name: 'playlistDetail', params:{ id: id }})
//      },
//      turnUser(userId){
//        console.log(userId)
//      }
    },
    mounted(){

      this.getPlaylistsWithPageNum(this.pageNum);

    },
    components: {
      PaginationWithTag,
      Pagination,
      playlist
    }
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
  .g-bd, .g-bd1, .g-bd2, .g-bd3, .g-bd4, .g-bd5, .g-bd6, .g-bd7 {
    width: 980px;
    min-height: 700px;
    _height: 700px;
    margin: 0 auto;
    background-color: #fff;
    border: 1px solid #d3d3d3;
    border-width: 0 1px;
  }

  .g-wrap {
    padding: 40px;
  }

  .f-pr {
    position: relative;
    zoom: 1;
  }

  div {
    display: block;
  }

  .u-title {
    height: 40px;
    border-bottom: 2px solid #c20c0c;
  }

  .f-cb {
  }

  .u-title h3 {
    float: left;
    font-size: 24px;
    font-weight: normal;
  }

  .f-ff2 {
    font-family: "Microsoft Yahei", Arial, Helvetica, sans-serif;
  }

  .u-title .menu {
    _position: absolute;
    font-size: 12px;
    font-weight: normal;
    margin: 2px 0 0 12px;
  }

  .u-btn2, .u-btn2:hover {
    text-decoration: none;
  }

  .u-btn2 {
    padding: 0 5px 0 0;
    white-space: nowrap;
  }

  .u-btn2, .u-btn2 i, .u-btn2 .icn, .u-btni, .u-btni i, .u-tag, .u-tag i, .u-btni-addply .ply {
    background: url(../image/button2.png) no-repeat 0 9999px;
  }

  .u-btn2-1 {
    color: #333;
    background-position: right -100px;
  }

  .u-title .menu i {
    color: #0c73c2 !important;
    padding: 0 10px 0 15px;
    _padding-right: 20px;
  }

  .u-btn2-1 i {
    color: #333;
    background-position: 0 -59px;
  }

  .u-btn2 i {
    padding: 0 15px 0 20px;
    pointer-events: none;
  }

  .u-btn2, .u-btn2 i {
    display: inline-block;
    height: 31px;
    line-height: 31px;
    overflow: hidden;
    vertical-align: top;
    text-align: center;
    cursor: pointer;
  }

  .u-icn, .u-icn2, .u-icn3 {
    display: inline-block;
    overflow: hidden;
    vertical-align: middle;
  }

  .u-icn, .u-title-1 .out .icon {
    background: url(../image/icon.png) no-repeat 0 9999px;
  }

  .u-title .menu .u-icn-38 {
    margin-left: 5px;
    _position: absolute;
    _top: 13px;
  }

  .u-icn-38 {
    width: 8px;
    height: 5px;
    background-position: -70px -543px;
  }

  .u-btn {
    display: inline-block;
  }

  /*.u-btn, div.u-page a, div.u-page a.js-selected, div.u-page a.znxt.js-disabled, div.u-page a.zprv.js-disabled {*/
  /*background: url(../image/button.png) no-repeat 0 9999px;*/
  /*}*/

  .f-fr {
    float: right;
  }

  .u-title .u-btn-hot .a1, .u-title .u-btn-time .a1, .u-title .u-btn-new .a2, .u-title .u-btn-area .a2, .u-title .u-btn-song .a1 {
    color: #fff;
  }

  .u-title .u-btn .a1, .u-title .u-btn .a2 {
    float: left;
    width: 46px;
    height: 29px;
    line-height: 29px;
    text-align: center;
  }

  .f-cb:after {
    clear: both;
    content: '.';
    display: block;
    height: 0;
    visibility: hidden;
  }

  .p-pl .m-cvrlst {
    margin: 30px 0 0 -50px;
  }

  .m-cvrlst li {
    float: left;
    display: inline-block;
    width: 140px;
    height: 188px;
    overflow: hidden;
    padding: 0 0 30px 50px;
    line-height: 1.4;
  }

  .u-cover-1 {
    width: 140px;
    height: 140px;
  }

  .u-cover {
    position: relative;
    display: block;
  }

  .u-cover img {
    display: block;
    width: 100%;
    height: 100%;
  }

  img, .txt {
    border: 0;
  }

  .u-cover-1 .msk {
    background-position: 0 0;
  }

  .u-cover .msk {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
  }

  .u-cover .bottom, .u-cover .msk, .n-musicsd .lst .avatar .msk {
    background: url(../image/coverall.png) no-repeat;
  }

  .u-cover .bottom {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 27px;
    background-position: 0 -537px;
    color: #ccc;
  }

  .u-cover .icon-play:hover {
    background-position: 0 -60px;
  }

  .u-cover .icon-play {
    position: absolute;
    right: 10px;
    bottom: 5px;
    width: 16px;
    height: 17px;
    background-position: 0 0;
  }

  .u-cover .icon-headset, .u-cover .icon-play {
    display: inline-block;
  }

  .u-cover .ply, .u-cover .icon-headset, .u-cover .icon-play, .u-face .msk, .n-note .head .msk, .icn-vip, .icn-daren, .u-checkbox {
    background: url(../image/iconall.png) no-repeat;
  }

  .u-cover .icon-headset {
    float: left;
    width: 14px;
    height: 11px;
    background-position: 0 -24px;
    margin: 9px 5px 9px 10px;
  }

  .u-cover .nb {
    float: left;
    margin: 7px 0 0 0;
  }

  .m-cvrlst li .dec {
    margin: 8px 0 3px;
    font-size: 14px;
  }

  .m-cvrlst li p {
    width: 100%;
  }

  .m-cvrlst li .tit {
    display: inline-block;
    max-width: 100%;
    _width: 100%;
    vertical-align: middle;
  }

  .s-fc0, a.s-fc0:hover {
    color: #000;
  }

  .f-thide {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    word-wrap: normal;
  }

  .s-fc4, a.s-fc4:hover {
    color: #999;
  }

  .m-cvrlst li .nm {
    display: inline-block;
    max-width: 85%;
    vertical-align: middle;
  }

  .m-cvrlst li .nm-icn {
    max-width: 76%;
  }

  .s-fc3, a.s-fc3:hover {
    color: #666;
  }

  .f-thide {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    word-wrap: normal;
  }

  .m-cvrlst li p .u-icn {
    margin-top: -1px;
    _margin-top: -3px;
  }

  .u-icn-84 {
    width: 12px;
    height: 13px;
    background-position: -65px -840px;
  }

  .u-icn, .u-icn2, .u-icn3 {
    display: inline-block;
    overflow: hidden;
    vertical-align: middle;
  }

  div.u-page {
    margin: 20px 0;
    text-align: center;
  }

  /*.u-btn, div.u-page a, div.u-page a.js-selected, div.u-page a.znxt.js-disabled, div.u-page a.zprv.js-disabled {*/
  /*background: url(../image/button.png) no-repeat 0 9999px;*/
  /*}*/

  div.u-page .zbtn {
    width: 69px;
    height: 24px;
    line-height: 24px;
    color: #333;
    text-align: left;
    padding: 0;
  }

  div.u-page .zbtn, div.u-page .zpgi {
    margin: 0 1px 0 2px;
    display: inline-block;
    border: 1px solid #ccc;
    border-radius: 2px;
    vertical-align: middle;
  }

  .u-btn, div.u-page a, div.u-page a.js-selected, div.u-page a.znxt.js-disabled, div.u-page a.zprv.js-disabled {
    background: url(../image/button.png) no-repeat 0 9999px;
  }

  .u-btn-hot {
    width: 93px;
    height: 29px;
    background-position: 0 0;
  }

  .u-btn-time {
    width: 93px;
    height: 29px;
    background-position: 0 -32px;
  }

  div.u-page .zpgi {
    height: 22px;
    padding: 0 8px;
    background-color: #fff;
    line-height: 22px;
  }

  div.u-page .zpgi:hover {
    border-color: #666;
  }

  div.u-page a:hover {
    text-decoration: none;
  }

  div.u-page a.zprv.js-disabled, div.u-page a.zprv.js-disabled:hover {
    background-position: 0 -620px;
    color: #cacaca;
    cursor: default;
  }

  div.u-page a.js-selected, div.u-page a.js-selected:hover {
    background-position: 0 -650px;
    border-color: #A2161B;
    color: #fff;
    cursor: default;
  }

  div.u-page .zbtn, div.u-page .zpgi {
    margin: 0 1px 0 2px;
    display: inline-block;
    border: 1px solid #ccc;
    border-radius: 2px;
    vertical-align: middle;
  }

  div.u-page .zbtn {
    width: 69px;
    height: 24px;
    line-height: 24px;
    color: #333;
    text-align: left;
    padding: 0;
  }

  div.u-page .zprv {
    width: 47px;
    padding-left: 22px;
    background-position: 0 -560px;
  }

  div.u-page .znxt {
    width: 57px;
    padding-left: 12px;
    background-position: -75px -560px;
  }

  .tag-cascader {
    width: 100px;
  }

  .tag-cascader-warp {
    /*margin-bottom: 20px;*/

  }
</style>
